import {BasePlugin} from 'amis-editor';

export class LineChartRendererPlugin extends BasePlugin {
  // 这里要跟对应的渲染器名字对应上
  // 注册渲染器的时候会要求指定渲染器名字
  rendererName = 'line-chart-renderer';

  // 暂时只支持这个，配置后会开启代码编辑器
  $schema = '/schemas/UnkownSchema.json';

  // 用来配置名称和描述
  name = '折线图表';
  description = '这只是个示例';

  // tag，决定会在哪个 tab 下面显示的
  tags = ['ECharts'];

  // 图标
  icon = 'fa fa-user';

  // 用来生成预览图的
  previewSchema = {
    type: 'line-chart-renderer',
    target: 'demo',
    dataset: "riskcontrol",
    primary: true,
    digitalItem: []
  };

  // 拖入组件里面时的初始数据
  scaffold = {
    type: 'line-chart-renderer',
    target: '哈哈哈',
    dataset: [
      {
        // 按行的 key-value 形式（对象数组），这是个比较常见的格式。
        source:  [
          { description: 'Matcha Latte1', riskLevelName: 'Matcha Latte 2', ruleName: 400, projectName: 10.8 },
          { description: 'Milk Tea', riskLevelName: 'Milk Tea 2', ruleName: 300, projectName: 30.4 },
          { description: 'Cheese Cocoa', riskLevelName: 'Cheese Cocoa 2', ruleName: 200, projectName: 50.2 },
          { description: 'Walnut Brownie', riskLevelName: 'Walnut Brownie 2', ruleName: 100, projectName: 76.9 }
        ]
      }
    ],
    primary: true,
    digitalItem: []
  };

  // 右侧面板相关
  panelTitle = '自定义组件';
  panelBody = [
    {
      type: 'tabs',
      tabsMode: 'line',
      className: 'm-t-n-xs',
      contentClassName: 'no-border p-l-none p-r-none',
      tabs: [
        {
          title: '常规',
          body: [
            {
              "name": "title",
              "type": "input-text",
              "placeholder": "标题",
              "value": "",
              "columnClassName": "w-sm"
            },
            {
              "type": "panel",
              "title": "数据集",
              "body": [
              {
                "label": "数据集",
                "type": "select",
                "name": "dataSetName",
                "options": [
                  {
                    "label": "审计线索",
                    "value": "rpt_audit_result"
                  },
                  {
                    "label": "持续监控",
                    "value": "rpt_risk_control_result"
                  },
                  {
                    "label": "事中审核",
                    "value": "rpt_internal_control_result"
                  }
                ]
              },
              {
                "label": "维度",
                "type": "select",
                "name": "dimension",
                "options": [
                  {
                    "label": "风险等级",
                    "value": "risklevelname"
                  },
                  {
                    "label": "风险描述",
                    "value": "description"
                  },
                  {
                    "label": "项目名称",
                    "value": "projectname"
                  },
                  {
                    "label": "规则名称",
                    "value": "rulename"
                  },
                  {
                    "label": "预警时间",
                    "value": "currentresulttime"
                  },
                  {
                    "label": "风险所属单位名称",
                    "value": "s_organization_name"
                  },
                  {
                    "label": "预警次数",
                    "value": "dataLogickeycount"
                  },
                  {
                    "label": "风控领域",
                    "value": "riskcontrol"
                  },
                  {
                    "label": "核实状态",
                    "value": "resolutionkind"
                  },
                  {
                    "label": "首次预警时间",
                    "value": "datalogickeyfirsttime"
                  }
                ]
              },
              {
                "type": "input-text",
                "name": "dimensionName",
                "label": "维度名称"
              },
              {
                "type": "combo",
                "name": "digitalItem",
                "label": "数值项",
                "multiple": true,
                "multiLine": true,
                "value": [
                  {}
                ],
                "items": [
                  {
                    "placeholder": "对应y轴",
                    "name": "yAxisIndex",
                    "type": "select",
                    "defaultValue": 0,
                    "options": [
                      {
                        "label": "y轴主轴",
                        "value": 0
                      },
                      {
                        "label": "y轴副轴",
                        "value": 1
                      }
                    ]
                  },
                  {
                    "placeholder": "图形",
                    "name": "chartType",
                    "type": "select",
                    "options": [
                      {
                        "label": "折线",
                        "value": "line"
                      },
                      {
                        "label": "柱状",
                        "value": "bar"
                      }
                    ]
                  },
                  {
                    "name": "name",
                    "type": "input-text",
                    "placeholder": "名称",
                    "value": "",
                    "columnClassName": "w-sm"
                  },
                  {
                    "placeholder": "字段",
                    "type": "select",
                    "name": "column",
                    "options": [
                      {
                        "label": "风险等级",
                        "value": "riskLevelName"
                      },
                      {
                        "label": "风险描述",
                        "value": "description"
                      },
                      {
                        "label": "项目名称",
                        "value": "projectName"
                      },
                      {
                        "label": "规则名称",
                        "value": "ruleName"
                      },
                      {
                        "label": "预警时间",
                        "value": "currentResultTime"
                      },
                      {
                        "label": "风险所属单位名称",
                        "value": "s_organization_name"
                      },
                      {
                        "label": "预警次数",
                        "value": "dataLogicKeyCount"
                      },
                      {
                        "label": "风控领域",
                        "value": "riskcontrol"
                      },
                      {
                        "label": "核实状态",
                        "value": "resolutionKind"
                      },
                      {
                        "label": "首次预警时间",
                        "value": "dataLogicKeyFirstTime"
                      }
                    ]
                  },
                  {
                    "name": "oprate",
                    "type": "select",
                    "options": [
                      {
                        "label": "计数",
                        "value": "count"
                      },
                      {
                        "label": "唯一值计数",
                        "value": "count2"
                      },
                      {
                        "label": "合计",
                        "value": "sum"
                      }
                    ]
                  }
                ]
              }]
            }
          ]
        },
        {
          title: 'x轴',
          body: [
            
          ]
        },
        {
          title: 'y轴',
          body: [
            {
              "name": "y-name",
              "type": "input-text",
              "placeholder": "名称",
              "value": "",
              "columnClassName": "w-sm"
            },
            {
              "name": "y-unit",
              "type": "input-text",
              "placeholder": "单位",
              "value": "",
              "columnClassName": "w-sm"
            }
          ]
        },
        {
          title: '副y轴(右边展示)',
          body: [
            {
              "name": "y2-name",
              "type": "input-text",
              "placeholder": "名称",
              "value": "",
              "columnClassName": "w-sm"
            },
            {
              "name": "y2-unit",
              "type": "input-text",
              "placeholder": "单位",
              "value": "",
              "columnClassName": "w-sm"
            }
          ]
        }
      ]
    }
  ];
}